package com.ruoyi.print.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import com.ruoyi.common.utils.StringUtils;
import java.util.List;
import java.util.Map;
import com.ruoyi.print.mapper.PrintTemplateMapper;
import com.ruoyi.print.domain.PrintTemplate;
import com.ruoyi.print.service.IPrintTemplateService;

/**
 * 打印模版Service业务层处理
 *
 * @author husky
 * @date 2023-11-04
 */
@Service
public class PrintTemplateServiceImpl extends ServiceImpl<PrintTemplateMapper, PrintTemplate> implements IPrintTemplateService {

    @Autowired
    private PrintTemplateMapper printTemplateMapper;

    /**
     * 查询打印模版列表
     *
     * @param printTemplate 打印模版
     * @return 打印模版
     */
    @Override
    public List<PrintTemplate> selectPrintTemplateList(PrintTemplate printTemplate)
    {
        List<PrintTemplate> printTemplateList = printTemplateMapper.selectList(buildQueryWrapper(printTemplate));
        return printTemplateList;
    }


    private LambdaQueryWrapper<PrintTemplate> buildQueryWrapper(PrintTemplate query) {
        Map<String, Object> params = query.getParams();
        LambdaQueryWrapper<PrintTemplate> lqw = Wrappers.lambdaQuery();
        lqw.like(StringUtils.isNotBlank(query.getName()), PrintTemplate::getName, query.getName());
        lqw.eq(query.getType() != null, PrintTemplate::getType, query.getType());
        lqw.eq(StringUtils.isNotBlank(query.getTemplate()), PrintTemplate::getTemplate, query.getTemplate());
        lqw.orderByDesc(PrintTemplate::getCreateTime);
        return lqw;
    }

}
